#! /bin/bash
# Transforms the output of "fsc --help" into nprof
# usage fsc --help | ./options_man.sh

ignore=1

# add a line jump after the option
sed 's/^\(--\? \?[^ ]*\) */\1\n/' |
while read line; do
    # skipping empty lines
    [[ "$line" = "" ]] && continue

    # new section
    if echo "$line" | grep -q -- '-$'; then
	echo "$line" | sed 's/^- \(.*\) -$/.SS \1/'
	ignore=0
	continue
    fi

    # ignoring lines before the 1st section
    [[ "$ignore" -eq 1 ]] && continue

    # new option
    if echo "$line" | grep -q -- '^-'; then
	echo ".TP"
	echo ".I $line"
	continue
    fi

    # description
    echo "$line"
done
